﻿using System;
using System.Linq;
using System.Web.UI.HtmlControls;
using FranceTriple.Dal;

namespace TeamFranceTriple
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        public Requester Requester { get; set; }
        private HtmlLink newStyleSheet, newStyleSheet2;
        private HtmlMeta metaDescription, metaKeywords, metaAuthor, metaGenerator;

        protected void Page_Load(object sender, EventArgs e)
        {
            FrenchLanguageHyperLink.NavigateUrl = Request.RawUrl.ToLower().Replace("en-us", "fr-fr");
            EnglishLanguageHyperLink.NavigateUrl = Request.RawUrl.ToLower().Replace("fr-fr", "en-us");

            HomeLink1.NavigateUrl = "~/" + Requester.Culture + "/home/";
            ForumLink1.NavigateUrl = "~/" + Requester.Culture + "/forum/";
            EventLink1.NavigateUrl = "~/" + Requester.Culture + "/eventlist/";
            PictureLink1.NavigateUrl = "~/" + Requester.Culture + "/picturelist/";
            FriendlyTeamLink1.NavigateUrl = "~/" + Requester.Culture + "/labaff/";
            MemberLink1.NavigateUrl = "~/" + Requester.Culture + "/memberlist/";
            AboutLink1.NavigateUrl = "~/" + Requester.Culture + "/about/";
            FanLink1.NavigateUrl = "~/" + Requester.Culture + "/fanlist/";

            SignupLink.NavigateUrl = "~/" + Requester.Culture + "/register/";
            SignupLink2.NavigateUrl = "~/" + Requester.Culture + "/register/";

            PictureLink1.Visible = Requester.Roles.Contains("Member");
            EventLink1.Visible = Requester.Roles.Contains("Member");

            SignupLink.Visible = (Session["AnonymousID"] != null);
            SignupLink2.Visible = (Session["AnonymousID"] != null);

            metaDescription = new HtmlMeta();
            metaDescription.Name = "DESCRIPTION";
            metaDescription.Content = "MetaDescription".ToLocalizedString().TextToHtml();
            Page.Header.Controls.Add(metaDescription);

            metaKeywords = new HtmlMeta();
            metaKeywords.Name = "KEYWORDS";
            metaKeywords.Content = "metaKeywords".ToLocalizedString().TextToHtml();
            Page.Header.Controls.Add(metaKeywords);

            metaAuthor = new HtmlMeta();
            metaAuthor.Name = "AUTHOR";
            metaAuthor.Content = "metaAuthor".ToLocalizedString().TextToHtml();
            Page.Header.Controls.Add(metaAuthor);

            metaGenerator = new HtmlMeta();
            metaGenerator.Name = "GENERATOR";
            metaGenerator.Content = "metaGenerator".ToLocalizedString().TextToHtml();
            Page.Header.Controls.Add(metaGenerator);

            // Ajouter la feuille de style commune
            newStyleSheet = new HtmlLink();
            newStyleSheet.Href = "~/Styles/Site.css";
            newStyleSheet.Attributes.Add("type", "text/css");
            newStyleSheet.Attributes.Add("rel", "stylesheet");
            Page.Header.Controls.Add(newStyleSheet);

            // Selectionner automatiquement une feuille de style sans fond d'écran pour les mobiles et avec pour les autres
            newStyleSheet2 = new HtmlLink();
            if (Request.Browser.IsMobileDevice)
            {
                newStyleSheet2.Href = "~/Styles/Site_Mobile.css";
            }
            else
            {
                newStyleSheet2.Href = "~/Styles/Site_Pc.css";
            }
            newStyleSheet2.Attributes.Add("type", "text/css");
            newStyleSheet2.Attributes.Add("rel", "stylesheet");
            Page.Header.Controls.Add(newStyleSheet2);
        }
    }
}
